﻿using System;
using System.Collections.Generic;

public class CampInfo
{
    private Score score = new Score(0, 0);
    private int camp;
    private int team;
    private HashSet<BaseChess> onlineChessSet = new HashSet<BaseChess>();
    private HashSet<BaseChess> offlineChessSet = new HashSet<BaseChess>();
    public CampInfo(int camp, int team, List<BaseChess> allChessList, BaseChessBoard chessBoard)
    {
        this.camp = camp;
        this.team = team;
        for (int i = 0; i < allChessList.Count; i++)
        {
            offlineChessSet.Add(allChessList[i]);
        }
    }
    public void Init(List<BaseChess> onChessList, BaseChessBoard chessBoard)
    {
        for (int i = 0; i < onChessList.Count; i++)
        {
            ChessOn(onChessList[i], chessBoard);
        }
    }
    public HashSet<BaseChess> DirectGetOnlineChessSet()
    {
        return onlineChessSet;
    }
    public HashSet<BaseChess> DirectGetOfflineChessSet()
    {
        return offlineChessSet;
    }
    public void ChessOn(BaseChess chess, BaseChessBoard chessBoard)
    {
        if (!offlineChessSet.Contains(chess))
        {
            throw new Exception();
        }
        offlineChessSet.Remove(chess);
        onlineChessSet.Add(chess);
        score = score.AddResult(chess.GetScore(chessBoard));
    }
    public void ChessOff(BaseChess chess, BaseChessBoard chessBoard)
    {
        if (!onlineChessSet.Contains(chess))
        {
            throw new Exception();
        }
        score = score.SubResult(chess.GetScore(chessBoard));
        onlineChessSet.Remove(chess);
        offlineChessSet.Add(chess);
    }
    public List<BaseChess> GetAllChessList()
    {
        List<BaseChess> chessList = new List<BaseChess>();
        chessList.AddRange(onlineChessSet);
        chessList.AddRange(offlineChessSet);
        return chessList;
    }
    public int GetCamp()
    {
        return camp;
    }
    public int GetTeam()
    {
        return team;
    }
    public Score GetCampScore()
    {
        return score;
    }
}